﻿using System;
using System.Net;
using GalaSoft.MvvmLight.Messaging;
using JustinAngel.Neurons.Framework;
using JustinAngel.Neurons.Framework.Navigation;
using JustinAngel.UnitedNationsNews.AppCore;
using JustinAngel.UnitedNationsNews.Pages.WebBrowser;
using Ninject;

namespace JustinAngel.UnitedNationsNews.Services
{
    public class SocialShareService : ISocialShareService
    {
        [Inject]
        public IMessenger MessengerInstance { get; set; }

        [Inject]
        public ITaskInvoker TaskInvoker { get; set; }

        public void ShareOnTwitter(IShareableOnSocialNetworks data)
        {
            MessengerInstance.Send(new NavigateToMessage(PageSources.WebBrowserPage, new Uri(
                string.Format(@"http://m.twitter.com/share?url={0}&text={1}",
                                     HttpUtility.UrlEncode(data.Link.OriginalString),
                                     HttpUtility.UrlEncode(data.Title) + " via @JustinAngel's @UN news app @ ")
                                ,UriKind.Absolute)));
        }

        public void ShareOnFacebook(IShareableOnSocialNetworks data)
        {
            MessengerInstance.Send(new NavigateToMessage(PageSources.WebBrowserPage, new Uri(
                string.Format(@"http://m.facebook.com/sharer.php?u={0}&t={1}",
                                     HttpUtility.UrlEncode(data.Link.OriginalString),
                                     HttpUtility.UrlEncode(data.Title))
                                , UriKind.Absolute)));
        }

        public void ShareViaEmail(IShareableOnSocialNetworks data)
        {
            TaskInvoker.SendEmail(data.Title, 
                    "Hi, " + Environment.NewLine + Environment.NewLine 
                    + "I wanted to share this link from the Windows Phone 7 \"United Nations News\" app with you:" + Environment.NewLine
                    + Environment.NewLine + data.Title + Environment.NewLine
                    + "\t @ " + data.Link
                    + Environment.NewLine + Environment.NewLine
                    + data.Content
                    );
        }
    }
}
